home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 979 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. Path: cs.umd.edu!gilman
  2. From: gilman@cfar.umd.edu (Gil Carmel)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Template Class Linkage?
  5. Date: 8 Jan 1996 19:03:24 GMT
  6. Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
  7. Message-ID: <4crpps$7ni@mimsy.cs.umd.edu>
  8. References: <4cmnjs$mk7@mimsy.cs.umd.edu> <4cq4hs$raa@news2.deltanet.com>
  9. NNTP-Posting-Host: scribble.cfar.umd.edu
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Sergio Olivas (olivas@deltanet.com) wrote:
  13.  
  14. : >I'm just learning templates, and I'm having problems with linkage.
  15. : >When the template class member function bodies are included in the .h file,
  16. : >everything is fine.  But when the function bodies are in a separate .c file,
  17. : >calls to these functions from other files give an "undefined reference to
  18. : >function" error from the linker.  Do template class member functions have 
  19. : >to be in the ".h" file, or is this a problem with my compiler?
  20.  
  21. : Yes, this is a known 'feature' of C++ -- As far as the language
  22. : standard and all the compilers go. I understand an update to the C++
  23. : language will include some way of including the template stuff into
  24. : the .c (cpp) files, as well as provide the Standard Template library
  25. : as part of the language.
  26.  
  27. : later,
  28. :   sergio
  29.  
  30. Thanks.  One more question:
  31. What happens if two different files use the same template class function?
  32. If both need to include the function body, then it will be defined twice and
  33. the linker will produce an error.
  34.  
  35. Gil
  36.  
  37. --
  38. |-----------------------------------------------------------|
  39. | Gil Carmel             | gilman@wam.umd.edu        |
  40. | Computer Science Undergraduate | gilman@cfar.umd.edu        |
  41. | University of Maryland     |                |
  42. | College Park, MD         |                |
  43. |-----------------------------------------------------------|
  44. | |                \o              | |
  45. | |                 |\              | |
  46. | |                / \              | |
  47.